#include "BackstoryScene.h"
#include "IntroScene.h"

using namespace cocos2d;

CCScene* BackstoryScene::scene() {
	CCScene* scene = NULL;
	scene = CCScene::node();

	CCLayer *layer = BackstoryScene::node();
	scene->addChild(layer);

	return scene;
}

void BackstoryScene::onExit() {
	InputManager::getSingletonPtr()->removeKeyListener("Back Story");
}

void BackstoryScene::update(ccTime cct)  { 
	InputManager::getSingletonPtr()->capture(); 
}

bool BackstoryScene::keyPressed( const OIS::KeyEvent &e ) {
	
	if (e.key == OIS::KC_SPACE) {
		CCScene *newGameScene = IntroScene::scene();
		CCTransitionFade* myFade = CCTransitionFade::transitionWithDuration(3, newGameScene);

		CCDirector::sharedDirector()->replaceScene(myFade);

		return true;
	}

	return true;
}

bool BackstoryScene::keyReleased( const OIS::KeyEvent &e ) {
	return true;
}

bool BackstoryScene::init() {
	InputManager::getSingletonPtr()->addKeyListener(this, "Back Story");

	CCSprite *bgSprite = CCSprite::spriteWithFile("Images\\Intro Screen\\backstory_bg.png"); // lines = 18.5 pxs apart
	bgSprite->setPositionX(400);
	bgSprite->setPositionY(300);

	CCLabelBMFont *firstLine = CCLabelBMFont::labelWithString("In the world which you are about to enter, you will embark on a grand adventure with you as the hero.", 
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	CCLabelBMFont *secondLine = CCLabelBMFont::labelWithString("Speak to people and check things wherever you go, be it towns, roads, or caves. Gather information and hints from every source.", 
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	CCLabelBMFont *thirdLine = CCLabelBMFont::labelWithString("New Paths will open to you by helping people in need, overcoming challenges, and  solving mysteries.", 
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	CCLabelBMFont *fourthLine = CCLabelBMFont::labelWithString("At times, you will be challenged by others and attacked by wild creatures. Be brave and keep pushing on.", 
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	CCLabelBMFont *fifthLine = CCLabelBMFont::labelWithString("Through your adventure, we hope that you will interact with all sorts of people and achieve personal growth. That is our biggest objective.", 
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	CCLabelBMFont *sixthLine = CCLabelBMFont::labelWithString("Press Space, and let your adventure begin!",
		"Fonts\\pokemon.fnt", 575, CCTextAlignmentLeft);

	firstLine->setScale(.5f);
	firstLine->setColor(ccBLACK);
	firstLine->setPositionX(400);
	firstLine->setPositionY(425);

	secondLine->setScale(.5f);
	secondLine->setColor(ccBLACK);
	secondLine->setPositionX(375);
	secondLine->setPositionY(375);

	thirdLine->setScale(.5f);
	thirdLine->setColor(ccBLACK);
	thirdLine->setPositionX(375);
	thirdLine->setPositionY(315);

	fourthLine->setScale(.5f);
	fourthLine->setColor(ccBLACK);
	fourthLine->setPositionX(390);
	fourthLine->setPositionY(260);

	fifthLine->setScale(.5f);
	fifthLine->setColor(ccBLACK);
	fifthLine->setPositionX(385);
	fifthLine->setPositionY(204);

	sixthLine->setScale(.5f);
	sixthLine->setColor(ccBLACK);
	sixthLine->setPositionX(250);
	sixthLine->setPositionY(167);

	//myLabel->setPositionX(400);
	//myLabel->setPositionY(330);

	//myNewLabel->setPositionX(250);
	//myNewLabel->setPositionY(170);

	//myLabel->setColor(ccBLACK);
	//myNewLabel->setColor(ccBLACK);

	this->addChild(bgSprite, 0);
	this->addChild(firstLine, 1);
	this->addChild(secondLine, 1);
	this->addChild(thirdLine, 1);
	this->addChild(fourthLine, 1);
	this->addChild(fifthLine, 1);
	this->addChild(sixthLine, 1);

	this->scheduleUpdate();

	return true;
}

void BackstoryScene::menuCloseCallBack(CCObject* pSender) {
	CCDirector::sharedDirector()->end();
}